// TypeScript file
class BgView extends egret.Sprite
{

    private bg1: BackGroudView;
    private bg2: BackGroudView;
    private bg1Height: number = 0;
    private bg2Height: number = 0;

    constructor()
    {
        super();
    }


    public initView(curScene: number): void
    {
        this.bg2 = new BackGroudView(curScene);
        this.addChild(this.bg2);
        this.bg1 = new BackGroudView(curScene);
        this.addChild(this.bg1);

        this.bg1Height = this.bg1.height;
        this.bg1.y = -this.bg1Height + Const.SENT_HEIGHT;

        this.bg2Height = this.bg2.height;
        this.bg2.y = this.bg1.y - this.bg2Height;
    }

    public updata(): void
    {
        if (this.bg1.y >= Const.SENT_HEIGHT)
        {
            this.bg1.y = this.bg2.y - this.bg1Height;
        }

        if (this.bg2.y >= Const.SENT_HEIGHT)
        {
            this.bg2.y = this.bg1.y - this.bg2Height;
        }

        this.bg1.y += GameData.bgSpeed;
        this.bg2.y += GameData.bgSpeed;
    }

    public dispose(): void
    {
        this.removeChildren();
        this.bg1 = null;
        this.bg2 = null;
    }
}